package com.ruoyi.project.module.loginType.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.loginType.domain.LoginType;
import com.ruoyi.project.module.loginType.service.ILoginTypeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 代理用户 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-14
 */
@Controller
@RequestMapping("/module/loginType")
public class LoginTypeController extends BaseController
{
    private String prefix = "module/loginType";
	
	@Autowired
	private ILoginTypeService loginTypeService;
	
	@RequiresPermissions("module:loginType:view")
	@GetMapping()
	public String loginType()
	{
	    return prefix + "/loginType";
	}
	
	/**
	 * 查询代理用户列表
	 */
	@RequiresPermissions("module:loginType:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(LoginType loginType)
	{
		startPage();
        List<LoginType> list = loginTypeService.selectLoginTypeList(loginType);
		return getDataTable(list);
	}
	
	/**
	 * 新增代理用户
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存代理用户
	 */
	@RequiresPermissions("module:loginType:add")
	@Log(title = "代理用户", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(LoginType loginType)
	{		
		return toAjax(loginTypeService.insertLoginType(loginType));
	}

	/**
	 * 修改代理用户
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		LoginType loginType = loginTypeService.selectLoginTypeById(id);
		mmap.put("loginType", loginType);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存代理用户
	 */
	@RequiresPermissions("module:loginType:edit")
	@Log(title = "代理用户", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(LoginType loginType)
	{		
		return toAjax(loginTypeService.updateLoginType(loginType));
	}
	
	/**
	 * 删除代理用户
	 */
	@RequiresPermissions("module:loginType:remove")
	@Log(title = "代理用户", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(loginTypeService.deleteLoginTypeByIds(ids));
	}
	
}
